package cn.ms.doctor.Controller;

import cn.ms.doctor.Entity.User;
import cn.ms.doctor.Resolver.GetSessionUserInter;
import cn.ms.doctor.Service.PrescriptionService;
import cn.ms.doctor.Utils.DataStandardUtils;
import cn.ms.doctor.Utils.GlobalMessage;
import com.alibaba.fastjson.JSON;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Map;

@RestController
@RequestMapping("/Prescription")
public class PrescriptionController {

    @Resource
    PrescriptionService prescriptionService;

    @RequestMapping("/isLogin/getPrescriptions")
    public Object getPrescriptions(@GetSessionUserInter User user, @RequestBody Map<String, Object> params){

        if (DataStandardUtils.standardKeyIsEmpty(params,"pageIndex","pageSize")){
            return new GlobalMessage(200,2,"非法请求...",null);
        }

        return new GlobalMessage(200,0,null,prescriptionService.getPrescriptions(user.getUserId(),user.getRoleId(),params));
    }

    @RequestMapping("/isLogin/isDoctor/addPrescription")
    public Object addPrescription(@GetSessionUserInter User user,@RequestBody Map<String,Object> params){
        if (DataStandardUtils.standardKeyIsEmpty(params,"patientId","prescriptionDiagnosis","drugs")) {
            return new GlobalMessage(200,2,"非法请求...",null);
        }
        if(!prescriptionService.addPrescription(user,params)){
            return new GlobalMessage(200,3,"出现异常,请联系管理员处理...",null);
        }
        return new GlobalMessage(200,0,null,"添加成功");
    }
}
